﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using IDAL;
using Model;

namespace DAL
{
    public class TMO : BaseRepository<TMOInfo>, ITMO
    {
        private const string PARM_MO_MOID = "@MOID";
        private const string PARM_MO_PRODUCTTYPEID = "@ProductTypeID";
        private const string PARM_MO_PREFIXSN = "@PrefixSN";
        private const string PARM_MO_STARTSN = "@StartSN";
        private const string PARM_MO_STOPSN = "@StopSN";

        public IList<TMOInfo> LoadEntities()
        {
            return null;
        }

        /// <summary>
        /// Get an individual category based on a provided id
        /// </summary>
        /// <param name="categoryId">Category id</param>
        /// <returns>Details about the Category</returns>
        public TMOInfo LoadEntity<T1>(T1 mOID)
        {
            SqlParameter parm = GetParameter();
            //Bind the parameter
            parm.Value = mOID;
            return ExcuteSqlToGetEntity("TMO_selectbyID", parm);
        }




        //-------------------------------------重写超类基础操作---------------------------------------------------------

        public override TMOInfo GetEntityRecord(SqlDataReader rdr)
        {
            TMOInfo pro = new TMOInfo(rdr.GetValue(0).ToString(), rdr.GetValue(1).ToString(), rdr.GetValue(2).ToString(),rdr.GetInt32(3),rdr.GetInt32(4));
            return pro;
        }

        public override TMOInfo GetEntityRecord()
        {
            TMOInfo pro = new TMOInfo();
            return pro;
        }

        public override string GetInsertsp()
        {
            return "TMO_Insert";
        }

        public override string GetUpdatesp()
        {
            return null;
        }

        public override string GetDeletesp()
        {
            return "TMO_Delete";
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter Parm = new SqlParameter(PARM_MO_MOID, SqlDbType.NVarChar, 50);
            return Parm;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_MO_MOID, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_MO_PRODUCTTYPEID, SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_MO_PREFIXSN,SqlDbType.NVarChar,50),
                    new SqlParameter(PARM_MO_STARTSN,SqlDbType.Int,4),
                    new SqlParameter(PARM_MO_STOPSN,SqlDbType.Int,4)
                };
            return parms;
        }

        public override void SetParameters(TMOInfo mo, params SqlParameter[] Parms)
        {
            Parms[0].Value = mo.MOID;
            Parms[1].Value = mo.ProductTypeID;
            Parms[2].Value = mo.PrefixSN;
            Parms[3].Value = mo.StartSN;
            Parms[4].Value = mo.StopSN;
        }
    }
}
